
function [T,x,P,pi,fval]  = eval_1s_2c_private_ss_nogL(xval,M_,ys)

% we need to solve for two wages
% for multi-sectors

NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
  paramname = M_.param_names{ii};
  eval([ paramname ' = M_.params(' int2str(ii) ');']);
end

NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically
for ii = 1:NumberOfEndogenousVariables
  varname = M_.endo_names{ii};
  eval([varname '= ys(' int2str(ii) ');']);
end


global L n alpha  d

% guess wage and share of labor in each sector

w(1:n,1) = xval(1:n); % row vector
taf = 0;

rL = rbest*L;

T = alpha.*rL/delta1;

sextax = zeros(n);
for i=1:n-1
    sextax(i+1) = taux;
end
staf = zeros(n);

for i=1:n-1
    staf(i+1) = taf;
end

pi = zeros(n,n); % (1,2,3): country 2 export to ecountry 1 in sector 3, NOTE country order is opposite to our note
%d, matrix of n times n, dij country j ship to country i


xnimatrix1= T'.*((w'.*(1+sextax).*(1+staf).*d).^(-theta));
 xn1 =sum(xnimatrix1,2).*ones(n,n);

pimatrix1 = xnimatrix1./xn1;
pi = pimatrix1;
xnimatrix= xnimatrix1;

betas =1;
x  =  (1+theta)/theta*w.*(L-sum(rL,2));

for m=2:n
    x(1)=x(1)+betas(1)*taux/(1+taux)*pi(m,1)*x(m);
end
tempt=0;

for m=2:n
    tempt=tempt+betas(1)*taf/(1+taf)*pi(1,m);
end

x(1)=x(1)/(1-tempt);

P=(sum(xnimatrix1,2)).^(-betas./theta);

fval(1) = P(1)-1;
fval(2) = pi(1,2)*x(1)-pi(2,1)*x(2);
